package com.sttk.fastMark.camera.dialog;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.NonNull;

import com.sttk.fastMark.camera.R;
import com.sttk.fastMark.camera.basic.dialog.BaseSmartDialog;
import com.sttk.fastMark.camera.databinding.DialogDeleteBinding;
import com.sttk.fastMark.camera.databinding.DialogFormatBinding;

public class FormatDialog extends BaseSmartDialog<DialogFormatBinding> implements View.OnClickListener {

    private String format = "jpg";

    public FormatDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected boolean canceledOnTouchOutside() {
        return true;
    }

    @Override
    protected int getGravity() {
        return Gravity.BOTTOM;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_format;
    }

    @Override
    protected void initView(View view) {
        mDataBinding.tvCancel.setOnClickListener(this);
        mDataBinding.tvConfirm.setOnClickListener(this);

        mDataBinding.tvFormat1.setOnClickListener(this);
        mDataBinding.tvFormat2.setOnClickListener(this);
        mDataBinding.tvFormat3.setOnClickListener(this);
        mDataBinding.tvFormat4.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tvCancel) {
            dismiss();
        } else if (id == R.id.tvConfirm) {
            dismiss();
            if (listener != null) {
                listener.clickConfirm(format);
            }
        } else if (id == R.id.tvFormat1) {
            clearSelection();
            mDataBinding.tvFormat1.setTextColor(Color.parseColor("#FFFFFF"));
            mDataBinding.tvFormat1.setBackgroundResource(R.drawable.format_sel);
            format = getContext().getString(R.string.format_text1);
        } else if (id == R.id.tvFormat2) {
            clearSelection();
            mDataBinding.tvFormat2.setTextColor(Color.parseColor("#FFFFFF"));
            mDataBinding.tvFormat2.setBackgroundResource(R.drawable.format_sel);
            format = getContext().getString(R.string.format_text2);
        } else if (id == R.id.tvFormat3) {
            clearSelection();
            mDataBinding.tvFormat3.setTextColor(Color.parseColor("#FFFFFF"));
            mDataBinding.tvFormat3.setBackgroundResource(R.drawable.format_sel);
            format = getContext().getString(R.string.format_text3);
        } else if (id == R.id.tvFormat4) {
            clearSelection();
            mDataBinding.tvFormat4.setTextColor(Color.parseColor("#FFFFFF"));
            mDataBinding.tvFormat4.setBackgroundResource(R.drawable.format_sel);
            format = getContext().getString(R.string.format_text4);
        }
    }

    private void clearSelection() {
        mDataBinding.tvFormat1.setTextColor(Color.parseColor("#000000"));
        mDataBinding.tvFormat1.setBackgroundResource(R.drawable.format_bg);
        mDataBinding.tvFormat2.setTextColor(Color.parseColor("#000000"));
        mDataBinding.tvFormat2.setBackgroundResource(R.drawable.format_bg);
        mDataBinding.tvFormat3.setTextColor(Color.parseColor("#000000"));
        mDataBinding.tvFormat3.setBackgroundResource(R.drawable.format_bg);
        mDataBinding.tvFormat4.setTextColor(Color.parseColor("#000000"));
        mDataBinding.tvFormat4.setBackgroundResource(R.drawable.format_bg);
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickConfirm(String format);
    }
}
